home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 2001-04-25 | 3.3 KB | 98 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- Persistable = 0 'NotPersistable
- DataBindingBehavior = 0 'vbNone
- DataSourceBehavior = 0 'vbNone
- MTSTransactionMode = 0 'NotAnMTSObject
- END
- Attribute VB_Name = "CStringBuilder"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- ' *************************************************************
- ' Copyright ⌐2000-2001, Karl E. Peterson
- ' http://www.mvps.org/vb/
- ' *************************************************************
- ' Author grants royalty-free rights to use this code within
- ' compiled applications. Selling or otherwise distributing
- ' this source code is not allowed without author's express
- ' permission.
- ' *************************************************************
- Option Explicit
-
- ' Win32 APIs
- Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
- ' *** Use proper function, depending on VB Version!
- Private Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Var() As Any) As Long
- ' Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Var() As Any) As Long
-
- ' Member variables
- Private m_Bump As Long
- Private m_Len As Long
- Private m_BufferLen As Long
- Private m_Buffer() As Byte
- Private m_Scratch() As Byte
-
- ' Internal class constants
- Private Const defBufferBump As Long = 2048
- Private Const BaseModule As String = "CStringBuilder"
- Private Const errArgumentOutOfRange As Long = vbObjectError + 512
-
- ' ************************************************
- ' Initialization and Termination
- ' ************************************************
- Private Sub Class_Initialize()
- ' dotNET uses a 16-char default size, but this
- ' class is really written for heavier use where
- ' longer strings will be more the norm.
- m_Bump = defBufferBump
- m_Len = 0
- ReDim m_Buffer(0 To m_Bump - 1) As Byte
- ReDim m_Scratch(0 To m_Bump - 1) As Byte
- m_BufferLen = UBound(m_Buffer) + 1
- End Sub
-
- ' ************************************************
- ' Properties
- ' ************************************************
- Public Property Let BufferBump(ByVal NewVal As Long)
- ' Accept new value (bytes) by which to resize buffer
- ' when adjustment is needed. Good to keep this
- ' fairly large in most cases.
- If NewVal > 0 Then
- ' Round up, if user passed odd number.
- If NewVal Mod 2 Then
- NewVal = NewVal + 1
- End If
- ' Store number of bytes to bump buffer by.
- m_Bump = NewVal
- End If
- End Property
-
- Public Property Get BufferBump() As Long
- ' Return number of bytes buffer gets bumped by.
- BufferBump = m_Bump
- End Property
-
- Public Property Let Capacity(ByVal NewVal As Long)
- Dim NewSize As Long
- ' This is an *expensive* routine, to be avoided
- ' at most reasonable costs. Adjusts the number of
- ' *bytes* in string buffer.
-
- If NewVal > 0 Then
- ' Adjust buffer to hold at least NewVal bytes,
- ' adjusting to next larger bufferbump size.
- NewSize = (NewVal \ m_Bump) * m_Bump
- jus and Term\ m_Bumis o*seIf
- End Property
-
- Public Property ump
- > 0 Theokeep this
- ' fairly large in most cases.
- If Ncemp = m_Bcei
- m_Bump = dmd_Bu2cty ump
- > 0 Theokeep this
- u